import {
	createRouter,
	createWebHashHistory
} from 'vue-router'
import Login from '../components/login.vue'
import Home from '../components/home.vue'
import Welcome from '../components/welcome.vue'
import Gener from '../components/admin/gener.vue'
import Family from '../components/admin/family.vue'
import People from '../components/admin/people.vue'
import Tongjir from '../components/admin/tongjir.vue'
import People1 from '../components/user/people1.vue'
import Gener1 from '../components/user/gener1.vue'
import Common from '../components/admin/common.vue'
import Tree from '../components/admin/Tree.vue'
import Event from '../components/admin/event.vue'
import Event1 from '../components/user/event1.vue'
import Relation from '../components/admin/relation.vue'
import Relation1 from '../components/user/relation1.vue'
const routes = [
{path: '/login',component: Login,},
{path: '/home',component: Home,
	redirect: '/welcome',	
		
children: [
	{path: '/welcome',component: Welcome,},		
	{path: '/Tree',component: Tree,},
	{path: '/gener',component: Gener,},
	{path: '/family',component: Family,},
	{path: '/people',component: People,},
	{path: '/tongjir',component: Tongjir,},
	{path: '/common',component: Common,},
	{path: '/people1',component: People1,},
	{path: '/gener1',component: Gener1,},
	{path: '/event',component: Event,},
	{path: '/event1',component: Event1,},
	{path: '/relation',component: Relation,},
	{path: '/relation1',component: Relation1,},

	],
	},

]

const router = createRouter({
	history: createWebHashHistory(),
	routes
})

// 挂载路由导航守卫
router.beforeEach((to, from, next) => {
	if (to.meta.title) {
		document.title = to.meta.title;
	}
	if (to.path == '/login') return next(); // 访问路径为登录
	// 获取flag
	const flagStr = window.sessionStorage.getItem("username"); // session取值
	if (!flagStr) return next('/login'); // 没登录去登录
	next();
})

export default router
